$package('itsm.system');

itsm.system.transMain=function(){
	this.opt='';
	return {
		//列表
		transMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'trans!findTransactionRecordPager.action',
				caption:'交易记录管理',
				colNames:['ID','会员ID','对象','类型','收入','支出','余额','操作时间','备注'],
			 	colModel:[
			 	          {name:'recordId',align:'center'},
			 	          {name:'loginName',align:'center'},
			 	          {name:'transactionObject',align:'center'},
			 	         {name:'transactionType',align:'center',formatter:i18nForma},
			 	          {name:'income',align:'center'},
			 	          {name:'expenditure',align:'center'},
			 	          {name:'balance',align:'center'},
			 	         {name:'optDate',align:'center',formatter:timeFormatter},
			 	          {name:'remark',align:'center'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "recordId"}),
				sortname:'recordId',
				pager:'#transMainPager'
				});
				$("#transMainGrid").jqGrid(params);
				$("#transMainGrid").navGrid('#transMainPager',navGridParams);
				//列表操作项
				$("#t_transMainGrid").css(jqGridTopStyles);
				$("#t_transMainGrid").html($('#transMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#transMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveRule';
			resetForm('#transMain_add_form');
			$('#transMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editRule';
			checkBeforeEditGrid('#transMainGrid',function(rowData){
				$.post('trans!findRuleByRuleCode.action','ruleDTO.ruleCode='+rowData.ruleCode,function(data){
					$('#transMain_ruleId').val(data.ruleId);
					$('#transMain_ruleName').val(data.ruleName);
					$('#transMain_ruleCode').val(data.ruleCode);
					$('#transMain_ruleValue').val(data.ruleValue);
				});
				$('#transMain_add_win').window('open');
			});	
		},
		
		//保存
		saveTrans:function(){
			if($('#transMain_add_win').form('validate')){
				var _param = $('#transMain_add_win form').serialize();
				$.post('trans!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#transMain_add_win').window('close');
					$('#transMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteTrans:function(){
			checkBeforeDeleteGrid('#transMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("trans!deleteTrans.action", pp, function(){
					$('#transMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#transMain_search_win').window('open');
		},
		//搜索
		searchTrans:function(){
			var sdata=$('#transMain_search_win form').getForm();
			var postData = $("#transMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'trans!findTransactionRecordPager.action';		
			$('#transMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		init:function(){
			itsm.system.transMain.transMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.transMain.init();
});